home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Programming / Programming Languages / XLISP 2.0 / XLISP Tools / Utility (UL) / SEXPRIM.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1988-04-07  |  1.2 KB  |  36 lines  |  [TEXT/ttxt]

  1. ;; Larry Mulcahy 1988
  2. ;; primitive s-expression functions for sequence
  3.  
  4. (provide 's-expression-primitive)
  5.  
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7. ; list:position
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ; return the 0-origin position of the first occurrence of the
  10. ; element e in the list l.
  11. ; If not found, return nil.
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. (defun list:position (e l)
  15.   (dotimes (i (length l) nil)
  16.        (if (equal e (nth i l))
  17.            (return i))))
  18.  
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ; list:position-if
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.  
  23. (defun list:position-if (test l)
  24.   (dotimes (i (length l) nil)
  25.        (if (funcall test (nth i l)) (return i))))
  26.  
  27. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28. ; list:position-if-not
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30.  
  31. (defun list:position-if-not (test l)
  32.   (dotimes (i (length l) nil)
  33.        (if (not (funcall test (nth i l))) (return i))))
  34.  
  35.  
  36.